@extends("admin.layout.main")

@section("content")
    <?php $role = Session::get('authModule');?>
    <!--主页面头部信息-->
    <div class="page-header">
        <h1>
            商品列表
        </h1>
    </div>
    <!-- /.page-header -->

    <div class="page-header">
        <form method="get" action="">
            <a class="btn btn-xs btn-success" href="{{ route('admin.goods.add') }}">
                新增商品
            </a>
            <div style="float: right">
                <label>
                    <select name="type" id="" style="height: 34px">
                        <option value="1" @if($where['type'] == 1)selected @endif >商品名称</option>
                        <option value="2" @if($where['type'] == 2)selected @endif>商品ID</option>
                    </select>
                    <input type="text" name="keyword" id="keyword" value="{{ $where['keyword'] }}">
                </label>
                <lable>
                    商品状态：
                    <select name="status" id="" style="height: 34px">
                        <option value="0">全部</option>
                        <option value="1" @if($where['status'] == 1)selected @endif>出售中</option>
                        <option value="2" @if($where['status'] == 2)selected @endif>已下架</option>
                    </select>
                </lable>
                <button class="btn btn-xs btn-primary" style="margin-top:-4px;">搜索</button>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <table id="simple-table" class="table  table-bordered table-hover" style="text-align: center;">
                <thead>
                <tr>
                    <th>商品ID</th>
                    <th>商品名称</th>
                    <th>商品价格</th>
                    <th>库存</th>
                    <th>商品状态</th>
                    <th>操作</th>
                </tr>
                </thead>

                <tbody>
                @foreach($data as $v)
                <tr>
                    <td>{{ $v->id }}</td>
                    <td>{{ $v->name }}</td>
                    <td>{{ $v->member_price }}</td>
                    <td>{{ $v->stock }}</td>
                    <td>@if($v->status==1) 出售中 @else 已下架 @endif</td>
                    <td>
                        <a class="btn btn-xs btn-primary" href="{{ route('admin.goods.edit',['id'=>$v->id]) }}">查看</a>
                        <a class="btn btn-xs btn-success" data-id="{{ $v->id }}" data-status="{{ $v->status }}" onclick="confirm_handle('确认将 {{ $v->name }}@if($v->status==1) 下架 @else 上架 @endif?',changeStatus,'',this)">@if($v->status==1) 下架 @else 上架 @endif</a>
                        <a class="btn btn-xs btn-danger" data-id="{{ $v->id }}" onclick="confirm_handle('确认删除 {{ $v->name }}?',del,'',this)">删除</a>
                    </td>
                </tr>
                @endforeach
                </tbody>
            </table>
            {{ $data->appends($where)->links('admin.layout.page') }}
        </div>
    </div>
    <script src="{{ config('global.assets_path') }}js/jquery.validate.min.js"></script>
    <script src="{{ config('global.assets_path') }}js/messages_zh.js"></script>
    <script src="/plugins/layui/layui.js"></script>
    <script src="/plugins/layui/layui_component.js"></script>
    <script src="/js/ajax.js"></script>
    <script>
        function changeStatus(obj) {
            var id = $(obj).data('id');
            var status = $(obj).data('status');
            var data = {'id':id,'status':status};
            var url = '{{ route('admin.goods.ajaxChangeSt') }}';
            ajaxRequest(data,url,'post');
        }
        function del(obj) {
            var id = $(obj).data('id');
            var data = {'id':id,'delete':1};
            var url = '{{ route('admin.goods.ajaxChangeSt') }}';
            ajaxRequest(data,url,'post');
        }
    </script>
@endsection
